﻿// Decompiled with JetBrains decompiler
// Type: CreateMfgByCoordinates.CApCreCreateMfgEnabler
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.CreateWeldPoint;
using EngineeringInternalExtension;
using System;
using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;


namespace CreateMfgByCoordinates;

public class CApCreCreateMfgEnabler : ITxCommandEnabler
{
  public bool Enable
  {
    get
    {
      bool enable = false;
      if (TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded())
      {
        enable = TxEngineeringDataInternal.GlobalGetPartsMode() != 2;
        if (enable && TxTcUtilities.IsTcAnyPlatform)
          enable = this.IsSelectionValid() || TxApplication.ActiveSelection.TotalCount == 0;
      }
      return enable;
    }
  }

  private bool IsSelectionValid()
  {
    bool flag = true;
    if (TxTcUtilities.IsTcAnyPlatform)
    {
      CApCreateWpTCLogic capCreateWpTcLogic = new CApCreateWpTCLogic();
      TxTypeFilter txTypeFilter1 = new TxTypeFilter();
      if (!capCreateWpTcLogic.IsWeldPointPrivate)
      {
        TxTypeFilter txTypeFilter2 = new TxTypeFilter();
        foreach (Type allowedType in capCreateWpTcLogic.WeldContainerValidator.AllowedTypes)
        {
          txTypeFilter2.AddIncludedType(allowedType);
          txTypeFilter1.AddIncludedType(allowedType);
        }
        TxObjectList filteredItems = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter2);
        flag = ((Collection<ITxObject>) filteredItems).Count == 0 || ((Collection<ITxObject>) filteredItems).Count == 1;
      }
      if (flag)
      {
        TxTypeFilter txTypeFilter3 = new TxTypeFilter();
        foreach (Type allowedType in capCreateWpTcLogic.WeldOperationValidator.AllowedTypes)
        {
          txTypeFilter3.AddIncludedType(allowedType);
          txTypeFilter1.AddIncludedType(allowedType);
        }
        TxObjectList filteredItems = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter3);
        flag = ((Collection<ITxObject>) filteredItems).Count == 0 || ((Collection<ITxObject>) filteredItems).Count == 1 && ((Collection<ITxObject>) filteredItems)[0].CanBeModified;
      }
      if (flag && ((Collection<ITxObject>) TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter1)).Count != TxApplication.ActiveSelection.Count)
        flag = false;
    }
    return flag;
  }
}
